package bTree.LeetCode;

public class 二叉树的直径 {
    int max = 0;

    public int diameterOfBinaryTree(TreeNode root) {
        roll(root);
        return max-1;
    }

    private int roll(TreeNode root) {
        if (null == root) return 0;
        int left = roll(root.left);
        int right = roll(root.right);
        max = Math.max(left + right + 1, max);
        return Math.max(left, right) + 1;
    }
}